<!DOCTYPE html>
<html lang=zh>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="用于计算常用的函数执行时间。1234567import timeimport timeitdef run_sleep(times):    time.sleep(times)    print(times)print(timeit.timeit(lambda :run_sleep(2),number&#x3D;5)) 熟悉下 lambda 的使用方法 Python3匿名函数lambda详解及使用示例概述匿名">
<meta property="og:type" content="article">
<meta property="og:title" content="python 使用小技巧，timeit计算程序代码的执行时间。">
<meta property="og:url" content="http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/index.html">
<meta property="og:site_name" content="Sampson&#39;s blog">
<meta property="og:description" content="用于计算常用的函数执行时间。1234567import timeimport timeitdef run_sleep(times):    time.sleep(times)    print(times)print(timeit.timeit(lambda :run_sleep(2),number&#x3D;5)) 熟悉下 lambda 的使用方法 Python3匿名函数lambda详解及使用示例概述匿名">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-06-08T13:16:27.911Z">
<meta property="article:modified_time" content="2020-06-08T13:11:57.000Z">
<meta property="article:author" content="Sampson.Z">
<meta property="article:tag" content="python">
<meta name="twitter:card" content="summary">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>python 使用小技巧，timeit计算程序代码的执行时间。</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
      
<link rel="stylesheet" href="/css/rtl.css">

    
    <!-- rss -->
    
    
<meta name="generator" content="Hexo 4.2.1"><link rel="alternate" href="/atom.xml" title="Sampson's blog" type="application/atom+xml">
</head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/projects-url">项目</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/categories/">分类</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        
        <li><a class="icon" href="/2020/06/07/python-urllib/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/" target="_blank" rel="noopener"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&text=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&title=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&is_video=false&description=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=python 使用小技巧，timeit计算程序代码的执行时间。&body=Check out this article: http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&title=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&title=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&title=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&title=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&name=python 使用小技巧，timeit计算程序代码的执行时间。&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&t=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#用于计算常用的函数执行时间。"><span class="toc-number">1.</span> <span class="toc-text">用于计算常用的函数执行时间。</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#熟悉下-lambda-的使用方法"><span class="toc-number">2.</span> <span class="toc-text">熟悉下 lambda 的使用方法</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#lambda-匿名函数。"><span class="toc-number">3.</span> <span class="toc-text">lambda 匿名函数。</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#可以将lambda直接传递给一个变量，像调用一般函数一样使用"><span class="toc-number">3.0.1.</span> <span class="toc-text">可以将lambda直接传递给一个变量，像调用一般函数一样使用</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1-结合三元表达式求两值中最小值"><span class="toc-number">3.1.</span> <span class="toc-text">1. 结合三元表达式求两值中最小值</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-对字典某一键值进行排序"><span class="toc-number">3.2.</span> <span class="toc-text">2. 对字典某一键值进行排序</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#result"><span class="toc-number">4.</span> <span class="toc-text">result</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        python 使用小技巧，timeit计算程序代码的执行时间。
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">Sampson's blog</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2020-06-08T13:16:27.911Z" itemprop="datePublished">2020-06-08</time>
        
      
    </div>


      

      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/python/" rel="tag">python</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h4 id="用于计算常用的函数执行时间。"><a href="#用于计算常用的函数执行时间。" class="headerlink" title="用于计算常用的函数执行时间。"></a>用于计算常用的函数执行时间。</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">import</span> timeit</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">run_sleep</span><span class="params">(times)</span>:</span></span><br><span class="line">    time.sleep(times)</span><br><span class="line">    print(times)</span><br><span class="line"></span><br><span class="line">print(timeit.timeit(<span class="keyword">lambda</span> :run_sleep(<span class="number">2</span>),number=<span class="number">5</span>))</span><br></pre></td></tr></table></figure>
<h4 id="熟悉下-lambda-的使用方法"><a href="#熟悉下-lambda-的使用方法" class="headerlink" title="熟悉下 lambda 的使用方法"></a>熟悉下 lambda 的使用方法</h4><p> Python3匿名函数lambda详解及使用示例<br>概述<br>匿名函数，顾名思义即没有名称的函数，和def定义的函数的最大区别在于匿名函数创建后返回函数本身（即匿名函数不需要return来返回值），表达式本身结果就是返回值，而def创建后则赋值给一个变量名，在Python中，我们利用关键词lambda创建匿名函数，以下是匿名函数lambda表达式的形式： lambda arg1,arg2,…..argn:expression 以下为一些lambda的特点：</p>
<p>lambda 是一个表达式，而不是一个语句，即我们可以在任何可以使用表达式的场景一样使用lambda。<br>lambda 的主体也是一个表达式，即和def定义的函数一样，lambda也有函数主体，不过lambda的主体仅仅是一个表达式，所以其使用的功能受到较大的限制。<br>‘’’</p>
<h4 id="lambda-匿名函数。"><a href="#lambda-匿名函数。" class="headerlink" title="lambda 匿名函数。"></a>lambda 匿名函数。</h4><h6 id="可以将lambda直接传递给一个变量，像调用一般函数一样使用"><a href="#可以将lambda直接传递给一个变量，像调用一般函数一样使用" class="headerlink" title="可以将lambda直接传递给一个变量，像调用一般函数一样使用"></a>可以将lambda直接传递给一个变量，像调用一般函数一样使用</h6><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">B = <span class="keyword">lambda</span> :<span class="literal">True</span></span><br><span class="line">print(B())</span><br></pre></td></tr></table></figure>
<p> 等价于</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">BF</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">print(BF())</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">sum_with_100 = <span class="keyword">lambda</span> x, y=<span class="number">100</span>: x + y</span><br><span class="line"><span class="comment"># 等同于：</span></span><br><span class="line"><span class="comment"># def sum_with_100(x, y=100): return x + y</span></span><br><span class="line">print(sum_with_100(<span class="number">200</span>))</span><br></pre></td></tr></table></figure>

<p>从后面传参<br>之前的示例我们将lambda匿名函数赋值一个变量，通过类似def定义的函数的方式传参，我们可以在lambda后面直接传递参数：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">two_sum = (<span class="keyword">lambda</span> x, y: x + y)(<span class="number">3</span>, <span class="number">4</span>)</span><br><span class="line">print(two_sum)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">sum</span><span class="params">(x)</span>:</span></span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">lambda</span> y: x + y</span><br><span class="line">sum_with_100 = sum(<span class="number">100</span>)</span><br><span class="line">print(sum_with_100)</span><br><span class="line">result = sum_with_100(<span class="number">200</span>)</span><br><span class="line">print(result)</span><br></pre></td></tr></table></figure>
<h5 id="1-结合三元表达式求两值中最小值"><a href="#1-结合三元表达式求两值中最小值" class="headerlink" title="1. 结合三元表达式求两值中最小值"></a>1. 结合三元表达式求两值中最小值</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">lower = <span class="keyword">lambda</span> x,y: x <span class="keyword">if</span> x&lt;y <span class="keyword">else</span> y</span><br><span class="line">print(lower(<span class="number">7</span>,<span class="number">100</span>))</span><br></pre></td></tr></table></figure>

<h5 id="2-对字典某一键值进行排序"><a href="#2-对字典某一键值进行排序" class="headerlink" title="2. 对字典某一键值进行排序"></a>2. 对字典某一键值进行排序</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">d = [&#123;<span class="string">"order"</span>:<span class="number">3</span>&#125;,&#123;<span class="string">"order"</span>:<span class="number">1</span>&#125;,&#123;<span class="string">"order"</span>:<span class="number">2</span>&#125;]</span><br><span class="line"><span class="comment"># 根据order键值排序</span></span><br><span class="line">d.sort(key=<span class="keyword">lambda</span> x:x[<span class="string">'order'</span>])</span><br><span class="line">print(d)</span><br></pre></td></tr></table></figure>

<h4 id="result"><a href="#result" class="headerlink" title="result"></a>result</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="number">2</span></span><br><span class="line"><span class="number">2</span></span><br><span class="line"><span class="number">2</span></span><br><span class="line"><span class="number">2</span></span><br><span class="line"><span class="number">2</span></span><br><span class="line"><span class="number">10.0492172</span></span><br><span class="line"><span class="literal">True</span></span><br><span class="line"><span class="literal">True</span></span><br><span class="line"><span class="number">300</span></span><br><span class="line"><span class="number">7</span></span><br><span class="line">&lt;function sum.&lt;locals&gt;.&lt;<span class="keyword">lambda</span>&gt; at <span class="number">0x0000018272C56AF0</span>&gt;</span><br><span class="line"><span class="number">300</span></span><br><span class="line"><span class="number">7</span></span><br><span class="line">[&#123;<span class="string">'order'</span>: <span class="number">1</span>&#125;, &#123;<span class="string">'order'</span>: <span class="number">2</span>&#125;, &#123;<span class="string">'order'</span>: <span class="number">3</span>&#125;]</span><br></pre></td></tr></table></figure>
  </div>
</article>












		<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
		<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
		<!--<script src="//cdn.jsdelivr.net/npm/leancloud-storage@latest/dist/av-min.js"></script>
    <script src='//cdn.jsdelivr.net/npm/valine@latest/dist/Valine.min.js'></script>-->
	<div id="vcomments"></div>
	<script>
		var notify = false == true ? true : false;
		var verify = false == true ? true : false;
		var visitor = true == true ? true : false;
  new Valine({
      el: '#vcomments',
				notify: notify,
				verify: verify,
    	app_id: 'MyX4PiXsizWYy8EuLEFEE05g-MdYXbMMI',
      app_key: 'rvmEQ2Sd345um4vPgXbnKbje',
			lang: 'en',
			placeholder: 'ヾﾉ≧∀≦)o快来评论一下吧!',
			avatar: 'monsterid',
			pageSize: 10,
			visitor: visitor
        });
    </script>






        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/projects-url">项目</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/categories/">分类</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#用于计算常用的函数执行时间。"><span class="toc-number">1.</span> <span class="toc-text">用于计算常用的函数执行时间。</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#熟悉下-lambda-的使用方法"><span class="toc-number">2.</span> <span class="toc-text">熟悉下 lambda 的使用方法</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#lambda-匿名函数。"><span class="toc-number">3.</span> <span class="toc-text">lambda 匿名函数。</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#可以将lambda直接传递给一个变量，像调用一般函数一样使用"><span class="toc-number">3.0.1.</span> <span class="toc-text">可以将lambda直接传递给一个变量，像调用一般函数一样使用</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1-结合三元表达式求两值中最小值"><span class="toc-number">3.1.</span> <span class="toc-text">1. 结合三元表达式求两值中最小值</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-对字典某一键值进行排序"><span class="toc-number">3.2.</span> <span class="toc-text">2. 对字典某一键值进行排序</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#result"><span class="toc-number">4.</span> <span class="toc-text">result</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/" target="_blank" rel="noopener"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&text=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&title=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&is_video=false&description=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=python 使用小技巧，timeit计算程序代码的执行时间。&body=Check out this article: http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&title=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&title=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&title=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&title=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&name=python 使用小技巧，timeit计算程序代码的执行时间。&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=http://yoursite.com/2020/06/08/python%E6%8A%80%E5%B7%A7-1/&t=python 使用小技巧，timeit计算程序代码的执行时间。" target="_blank" rel="noopener"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
    
    
    2016-2020
    Sampson.Z
<img src="https://static.dy208.cn/o_1dfilp8ruo521thr1hvf18ji17soa.png">
<a href="http://www.beian.miit.gov.cn/"  style="color:#f72b07" target="_blank">粤ICP备19066509号</a>

  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/projects-url">项目</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/categories/">分类</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
    <!-- styles -->

<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">


<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">


    <!-- jquery -->

<script src="/lib/jquery/jquery.min.js"></script>


<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>

<!-- clipboard -->

  
<script src="/lib/clipboard/clipboard.min.js"></script>

  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"复制到粘贴板!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "复制成功!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

<!-- Disqus Comments -->


</body>
</html>
